package com.vm.osm.business.controller;

import com.vm.osm.business.dto.req.orderInst.ReqAcceptByDept;
import com.vm.osm.business.dto.req.orderInst.ReqGetMyOrder;
import com.vm.osm.business.dto.req.orderInst.ReqRefuseByDept;
import com.vm.osm.business.dto.rsp.orderInst.RspAllOrderPage;
import com.vm.osm.business.dto.rsp.orderInst.RspMaintenancePage;
import com.vm.osm.business.dto.rsp.orderInst.RspOrderPage;
import com.vm.osm.business.service.IOrderFailureService;
import com.vm.osm.business.service.IOrderService;
import com.vm.osm.business.util.UserDataUtil;
import io.swagger.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by chenzui on 2018/4/1.
 */
@RestController
@RequestMapping("/v1.0")
@Api(value = "OrderInAllController",description = "工单管理模块",tags = {"OrderInAllController"})
public class OrderInAllController {

    private Logger LOG = Logger.getLogger(this.getClass());

    @Autowired
    private IOrderService orderService;

    @Autowired
    private IOrderFailureService orderFailureService;

    @ApiOperation(value = "查询本部门所有工单",notes = "查询本部门所有工单")
    @ApiImplicitParam(name = "reqGetMyOrder",value = "请求参数",required = true,dataType = "ReqGetMyOrder" )
    @RequestMapping(value = "/order/findPage",method = RequestMethod.POST)
    public RspAllOrderPage queryMyOrder(@RequestBody ReqGetMyOrder reqGetMyOrder, HttpServletRequest request){
        LOG.info("查询本部门所有工单："+UserDataUtil.getDepartmentId(request));
        reqGetMyOrder.setEnterprise_id(UserDataUtil.getUserSelectedEnterpriseId(request));
        reqGetMyOrder.setDepartment_id(UserDataUtil.getDepartmentId(request));
        return orderService.findPage(reqGetMyOrder);
    }


    @ApiOperation(value = "查询设备维护记录",notes = "查询设备维护记录，只查询已完成的故障单")
    @RequestMapping(value = "/equ/maintenance/record",method = RequestMethod.GET)
    public RspMaintenancePage queryMaintenance(
            @ApiParam(required=true, name="device_id", value="设备ID") @RequestParam("device_id") String deviceId,
            @ApiParam(required=true, name="page_num", value="page_num") @RequestParam("page_num") Integer pageNum,
            @ApiParam(required=true, name="page_size", value="page_size") @RequestParam("page_size") Integer pageSize){
        LOG.info("查询设备维护记录");
        return orderFailureService.queryOrderByDeviceId(pageNum,pageSize,deviceId);
    }

    @ApiOperation(value = "受理外部单据",notes = "受理外部单据")
    @ApiImplicitParam(name = "reqAcceptByDept",value = "reqAcceptByDept",dataType = "ReqAcceptByDept")
    @RequestMapping(value = "/order/out/accept",method = RequestMethod.PUT)
    public void acceptByDept(@RequestBody ReqAcceptByDept reqAcceptByDept,HttpServletRequest request){
        LOG.info("受理外部单据");
        orderService.acceptByDept(reqAcceptByDept,request);
    }

//    @ApiOperation(value = "拒绝受理外部单据",notes = "拒绝受理外部单据")
//    @ApiImplicitParam(name = "reqRefuseByDept",value = "reqRefuseByDept",dataType = "ReqRefuseByDept")
//    @RequestMapping(value = "/order/out/refuse",method = RequestMethod.PUT)
//    public void refuseByDept(@RequestBody ReqRefuseByDept reqRefuseByDept){
//        LOG.info("拒绝受理外部单据");
//        orderService.refuseByDept(reqRefuseByDept);
//    }
}
